package com.meepo.framework.design.tabs.sample.navadapters

import android.content.Context
import com.meepo.framework.design.helper.Utils
import com.meepo.framework.design.tabs.buildins.commonnavigator.abs.CommonNavigatorAdapter
import com.meepo.framework.design.tabs.buildins.commonnavigator.abs.IPagerIndicator
import com.meepo.framework.design.tabs.buildins.commonnavigator.abs.IPagerTitleView
import com.meepo.framework.design.tabs.buildins.commonnavigator.indicators.LinePagerIndicator
import com.meepo.framework.design.tabs.buildins.commonnavigator.titles.ColorTransitionPagerTitleView
import com.meepo.framework.design.tabs.buildins.commonnavigator.titles.SimplePagerTitleView
import com.meepo.framework.design.tabs.sample.TextTab

class ColorTransitionNavigatorAdapter(val tabs: List<TextTab>, val onItemClick: (index: Int) -> Unit) :
    CommonNavigatorAdapter() {
    override fun getCount(): Int = tabs.size

    override fun getTitleView(context: Context, index: Int): IPagerTitleView {
        val simplePagerTitleView: SimplePagerTitleView = ColorTransitionPagerTitleView(context)
        simplePagerTitleView.text = tabs[index].selectedText

        if (tabs[index].textSize > 0) simplePagerTitleView.textSize = tabs[index].textSize
        simplePagerTitleView.normalColor = tabs[index].unSelectedTextColor
        simplePagerTitleView.selectedColor = tabs[index].selectedTextColor

        simplePagerTitleView.setOnClickListener { onItemClick(index) }
        return simplePagerTitleView
    }

    override fun getIndicator(context: Context): IPagerIndicator {
        val indicator = LinePagerIndicator(context)
        indicator.mode = LinePagerIndicator.MODE_EXACTLY
        indicator.lineWidth = Utils.px(context, 10f)
        indicator.roundRadius = Utils.px(context, 1f)
        // todo indicator color
        indicator.setColors(tabs[0].selectedTextColor)
        return indicator
    }
}